//
//  AdoptPigCell.m
//  PigMarket
//
//  Created by mac on 2019/3/27.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "AdoptPigCell.h"


@interface AdoptPigCell ()
/**
 白色背景
 */
@property (nonatomic , strong) UIView *bgView;

/**
 title
 */
@property (nonatomic , strong) UILabel *titleLab;

/**
 生长周期
 */
@property (nonatomic , strong) UILabel *growthCycleLab;

/**
 排队人数
 */
@property (nonatomic , strong) UILabel *lineUpNumLab;

/**
 猪的图片
 */
@property (nonatomic , strong) UIImageView *pigImgView;

/**
 猪的简介
 */
@property (nonatomic , strong) UILabel *detailPigLab;

/**
 横线
 */
@property (nonatomic , strong) UIView *hLine;

/**
 领养Btn
 */
@property (nonatomic , strong) UIButton *adoptBtn;

/**
 已领养灰图层
 */
@property (nonatomic , strong) UIView *adpotedView;

/**
 已领养图片
 */
@property (nonatomic , strong) UIImageView *adoptedImgView;
@end
@implementation AdoptPigCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifierID = @"identifierID";
    AdoptPigCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierID];
    if (cell == nil) {
        cell = [[AdoptPigCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifierID];
    }
    cell.backgroundColor = [UIColor globalBackgroundColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
#pragma mark - init method
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
    
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.titleLab];
    [self.bgView addSubview:self.lineUpNumLab];
    [self.bgView addSubview:self.growthCycleLab];
    [self.bgView addSubview:self.pigImgView];
    [self.bgView addSubview:self.detailPigLab];
    [self.bgView addSubview:self.hLine];
    [self.bgView addSubview:self.adoptBtn];
}

- (void)initLayout {
   
    // 布局子控件
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(0);
    }];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(15);
        make.height.mas_equalTo(22);
    }];
    [self.lineUpNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(28);
    }];
    [self.growthCycleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.titleLab.mas_bottom).offset(3);
        make.height.mas_equalTo(17);
    }];
     [self.pigImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.growthCycleLab.mas_bottom).offset(10);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(130 * [JTool getScreenWidthScale]);
    }];
    [self.detailPigLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(self.pigImgView.mas_bottom).offset(13);
        make.height.mas_equalTo(40);
    }];
    [self.hLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(self.detailPigLab.mas_bottom).offset(12);
        make.height.mas_equalTo(1);
    }];
    [self.adoptBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.hLine.mas_bottom).offset(0);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(46);
        make.bottom.mas_equalTo(0);
    }];
    
}
- (void)adoptTapped {
    if (self.adoptBlock) {
        self.adoptBlock();
    }
}

#pragma mark - getter and setter
- (void)setVarietyModel:(PigVariety *)varietyModel {
    _varietyModel = varietyModel;
    [self.pigImgView sd_setImageWithURL:[NSURL URLWithString:varietyModel.nameimgName] placeholderImage:[UIImage imageNamed:@"placeholder_large"]];
    self.titleLab.text = varietyModel.varietiesName;
    self.lineUpNumLab.text = [NSString stringWithFormat:@"当前排队%@人",varietyModel.namepeoplenum];
    self.growthCycleLab.text = [NSString stringWithFormat:@"生长周期%@个月",varietyModel.cycle];
    self.detailPigLab.text = varietyModel.explainText;

}
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 12;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textColor = [UIColor textBlackColor];
        _titleLab.font = [UIFont largerFont];
    }
    return _titleLab;
}
- (UILabel *)lineUpNumLab {
    if (!_lineUpNumLab) {
        _lineUpNumLab = [[UILabel alloc] init];
        _lineUpNumLab.textColor = [UIColor colorWithHexString:@"#B2B2B2"];
        _lineUpNumLab.font = [UIFont smallFont];
    }
    return _lineUpNumLab;
}
- (UILabel *)growthCycleLab {
    if (!_growthCycleLab) {
        _growthCycleLab = [[UILabel alloc] init];
        _growthCycleLab.textColor = [UIColor colorWithHexString:@"#929292"];
        _growthCycleLab.font = [UIFont smallFont];
    }
    return _growthCycleLab;
}
- (UIImageView *)pigImgView {
    if (!_pigImgView) {
        _pigImgView = [[UIImageView alloc] init];
        _pigImgView.userInteractionEnabled = YES;
    }
    return _pigImgView;
}
- (UILabel *)detailPigLab {
    if (!_detailPigLab) {
        _detailPigLab = [[UILabel alloc] init];
        _detailPigLab.textColor = [UIColor colorWithHexString:@"#797979"];
        _detailPigLab.font = [UIFont middleFont];
        _detailPigLab.numberOfLines = 0;
    }
    return _detailPigLab;
}
- (UIView *)hLine {
    if (!_hLine) {
        _hLine = [[UIView alloc] init];
        _hLine.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.08];
    }
    return _hLine;
}
- (UIButton *)adoptBtn {
    if (!_adoptBtn) {
        _adoptBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_adoptBtn setTitle:@"领养" forState:UIControlStateNormal];
        [_adoptBtn setTitleColor:[UIColor colorWithHexString:@"#5E6066"] forState:UIControlStateNormal];
        _adoptBtn.titleLabel.font = [UIFont middleFont];
        [_adoptBtn addTarget:self action:@selector(adoptTapped) forControlEvents:UIControlEventTouchUpInside];
    }
    return _adoptBtn;
}

@end
